options compress=YES;
libname manasi ''; 

* STARTING WITH LARGE DATA SET, SELECT ALL KIDS WHO ARE ON SSI IN 
FY2004 OR FY2005 AND GET AVERAGES OF CHARACTERISTICS;
* purpose is to compare the full sample of FY04/05 SSI kids 
to CDR-eligible kids and complier sample;

data manasi.kids_complier_all0405_prep1;

* Select kids on in FY2004 or FY2005 who have a payment in those years;
	set manasi.kids_ssr_full_nwithsummfypar 
	(where=	(n_estpd_num<20061001 & n_estpd_next>=20011001 & dendte=0 &
				(n_combpay_2001>0 | n_combpay_2002>0 | n_combpay_2003>0 | n_combpay_2004>0 | n_combpay_2005>0 | n_combpay_2006>0)
			)
	drop=n_term18_: n_diag2_: n_diag2ever_:
	);

	* CREATE CHILD DEMOGRAPHIC VARIABLES;
	if sex='M' then n_male=1; else n_male=0;

	if dibmdr='3' then n_dibmdr_3=1; else n_dibmdr_3=0;
	if dibmdr='5' then n_dibmdr_5=1; else n_dibmdr_5=0;
	if dibmdr='7' then n_dibmdr_7=1; else n_dibmdr_7=0;
	if dibmdr^='3' & dibmdr^='5' & dibmdr^='7'
		then n_dibmdr_99=1; else n_dibmdr_99=0;

	rename n_firstpay_yr=n_firstpayyr;

	* CHANGE MISSING VALUES FOR HOUSEHOLD VARIABLES (DI & SSI RECEIPT) TO ZERO:
		THESE PEOPLE WEREN'T MATCHED TO MBR AND SSR WHICH MEANS NO RECEIPT;
	%macro miss(var);
		if &var._1985=. then &var._1985=0;
		if &var._1986=. then &var._1986=0;
		if &var._1987=. then &var._1987=0;
		if &var._1988=. then &var._1988=0;
		if &var._1989=. then &var._1989=0;
		if &var._1990=. then &var._1990=0;
		if &var._1991=. then &var._1991=0;
		if &var._1992=. then &var._1992=0;
		if &var._1993=. then &var._1993=0;
		if &var._1994=. then &var._1994=0;
		if &var._1995=. then &var._1995=0;
		if &var._1996=. then &var._1996=0;
		if &var._1997=. then &var._1997=0;
		if &var._1998=. then &var._1998=0;
		if &var._1999=. then &var._1999=0;
		if &var._2000=. then &var._2000=0;
		if &var._2001=. then &var._2001=0;
		if &var._2002=. then &var._2002=0;
		if &var._2003=. then &var._2003=0;
		if &var._2004=. then &var._2004=0;
		if &var._2005=. then &var._2005=0;
		if &var._2006=. then &var._2006=0;
		if &var._2007=. then &var._2007=0;
		if &var._2008=. then &var._2008=0;
		if &var._2009=. then &var._2009=0;
		if &var._2010=. then &var._2010=0;
		if &var._2011=. then &var._2011=0;
	%mend miss;

	%miss(n_hhmbayr);
	%miss(n_hhmbayr0206);
	%miss(n_hhdiindyr);
	%miss(n_hhdiindyr0206);
	%miss(n_hhcombpay);
	%miss(n_hhcombpay0206);
	%miss(n_hhonssi);
	%miss(n_hhonssi0206);
	%miss(n_sibpayall);
	%miss(n_sibnumon);
	%miss(n_par831di);
	%miss(n_par831di0206);
	%miss(n_par831ssi);
	%miss(n_par831ssi0206);
	%miss(n_kid831_di);
	%miss(n_kid831_ssi);

	%macro miss1992(var);
		if &var._1992=. then &var._1992=0;
		if &var._1993=. then &var._1993=0;
		if &var._1994=. then &var._1994=0;
		if &var._1995=. then &var._1995=0;
		if &var._1996=. then &var._1996=0;
		if &var._1997=. then &var._1997=0;
		if &var._1998=. then &var._1998=0;
		if &var._1999=. then &var._1999=0;
		if &var._2000=. then &var._2000=0;
		if &var._2001=. then &var._2001=0;
		if &var._2002=. then &var._2002=0;
		if &var._2003=. then &var._2003=0;
		if &var._2004=. then &var._2004=0;
		if &var._2005=. then &var._2005=0;
		if &var._2006=. then &var._2006=0;
		if &var._2007=. then &var._2007=0;
		if &var._2008=. then &var._2008=0;
		if &var._2009=. then &var._2009=0;
		if &var._2010=. then &var._2010=0;
		if &var._2011=. then &var._2011=0;
	%mend miss1992;

	%miss1992(n_sibappnum);

	if n_hhcombpay_2012=. then n_hhcombpay_2012=0;
	if n_hhcombpay0206_2012=. then n_hhcombpay0206_2012=0;
	if n_hhonssi_2012=. then n_hhonssi_2012=0;
	if n_hhonssi0206_2012=. then n_hhonssi0206_2012=0;
	if n_sibpayall_2012=. then n_sibpayall_2012=0;
	if n_sibnumon_2012=. then n_sibnumon_2012=0;
	if n_sibappnum_2012=. then n_sibappnum_2012=0;

	* CREATE PRE-TREATMENT OUTCOME VARIABLES;
	array hhunearninc0206(1985:2011) n_hhunearninc0206_1985-n_hhunearninc0206_2011;
	array hhunearnwokid0206(1985:2011) n_hhunearnwokid0206_1985-n_hhunearnwokid0206_2011;
	array hhmbayr0206(1985:2011) n_hhmbayr0206_1985-n_hhmbayr0206_2011;
	array combpay(1985:2011) n_combpay_1985-n_combpay_2011;
	array hhcombpay0206(1985:2011) n_hhcombpay0206_1985-n_hhcombpay0206_2011;
	array sibpayall(1985:2011) n_sibpayall_1985-n_sibpayall_2011;

	do i=1985 to 2011;
		hhunearninc0206(i)=hhmbayr0206(i)+combpay(i)+hhcombpay0206(i)+sibpayall(i);
	end;

	do i=1985 to 2011;
		hhunearnwokid0206(i)=hhmbayr0206(i)+hhcombpay0206(i)+sibpayall(i);
	end;

	n_paymonpre=sum(of n_paymon_1992-n_paymon_2001)/(2001-1992+1);
	n_combpaypre=sum(of n_combpay_1992-n_combpay_2001)/(2001-1992+1);

	n_hhdiamt0206pre=sum(of n_hhmbayr0206_1992-n_hhmbayr0206_2001)/(2001-1992+1);
	n_hhssipay0206pre=sum(of n_hhcombpay0206_1992-n_hhcombpay0206_2001)/(2001-1992+1);
	n_sibssipaypre=sum(of n_sibpayall_1992-n_sibpayall_2001)/(2001-1992+1);

	n_hhappdi0206pre=sum(of n_par831di0206_1992-n_par831di0206_2001)/(2001-1992+1);
	n_hhappssi0206pre=sum(of n_par831ssi0206_1992-n_par831ssi0206_2001)/(2001-1992+1);
	n_kidappssipre=sum(of n_kid831_ssi_1992-n_kid831_ssi_2001)/(2001-1992+1);
	n_sibappnumpre=sum(of n_sibappnum_1992-n_sibappnum_2001)/(2001-1992+1);

	n_totapp0206pre=n_hhappdi0206pre+n_hhappssi0206pre+n_sibappnumpre;

	n_hhunearn0206pre=sum(of n_hhunearninc0206_1992-n_hhunearninc0206_2001)/(2001-1992+1);
	n_hhunearnwokid0206pre=sum(of n_hhunearnwokid0206_1992-n_hhunearnwokid0206_2001)/(2001-1992+1);

	drop 
	n_par831di_: n_par831ssi_: n_par831di0206_: n_par831ssi0206_: 
	n_hhmbayr_: n_hhdiindyr_: n_hhmbayr0206_: n_hhdiindyr0206_: 
	n_hhonssi_: n_hhcombpay_: n_hhonssi0206_: n_hhcombpay0206_:
	n_sibpayall_: n_sibappnum_: n_sibnumon_: n_kid831_di_: n_kid831_ssi_:
	n_hhunearnwokid0206_: ;

run;

data manasi.kids_complier_all0405;
	set manasi.kids_complier_all0405_prep1
	(keep= 
	hun n_estpd_num n_estpd_next 
	dob dobyy sex dibmdr dibdig n_diag1_:
	n_firstage n_firstpayyr 
	par1_dobyy_: par2_dobyy_: par1_sex_: par2_sex_: toa
	n_male n_dibmdr_3 n_dibmdr_5 n_dibmdr_7 n_dibmdr_99 
	n_totapp0206pre n_hhunearnwokid0206pre 
	n_paymonpre n_combpaypre

	n_hhunearninc0206_1985-n_hhunearninc0206_2011
	)
	;
run;
